feat: update scheduled tasks to run in background#359
Merged
Conversation
Contributor
Greptile SummaryThis PR successfully isolates scheduled background tasks into dedicated hidden browser windows, preventing interference with the user's visible browser sessions. The implementation includes:
The changes are well-structured, with proper separation of concerns and consistent error handling throughout. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant ChatV2Service
participant Browser
participant AiSdkAgent
participant Session
User->>ChatV2Service: processMessage(isScheduledTask=true)
alt New Session
ChatV2Service->>Browser: createWindow({hidden: true})
Browser-->>ChatV2Service: {windowId}
ChatV2Service->>Browser: newPage('about:blank', {windowId})
Browser-->>ChatV2Service: pageId
ChatV2Service->>ChatV2Service: Create browserContext with windowId, pageId
ChatV2Service->>AiSdkAgent: create(browserContext)
AiSdkAgent->>AiSdkAgent: buildSystemPrompt(isScheduledTask, windowId)
AiSdkAgent-->>ChatV2Service: agent
ChatV2Service->>Session: store(agent, hiddenWindowId, browserContext)
end
ChatV2Service->>AiSdkAgent: appendUserMessage(messageContext)
ChatV2Service->>AiSdkAgent: stream response
AiSdkAgent-->>User: Execute task in hidden window
AiSdkAgent->>ChatV2Service: onFinish callback
ChatV2Service->>Session: Set hiddenWindowId = undefined
ChatV2Service->>Browser: closeWindow(windowId)
alt deleteSession called
User->>ChatV2Service: deleteSession()
ChatV2Service->>Session: Get hiddenWindowId
ChatV2Service->>Session: Set hiddenWindowId = undefined
ChatV2Service->>Browser: closeWindow(windowId)
ChatV2Service->>Session: delete()
end
Last reviewed commit: 7af229a |
Contributor
Author
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces major improvements to how scheduled background tasks are handled by the agent. It ensures scheduled tasks run in a dedicated, hidden browser window, keeping them isolated from the user's visible browser context. The changes also update the system prompt and browser context formatting to support this new behavior, and add proper cleanup of hidden windows after task completion. Additionally, there are minor UI improvements for scheduled task result dialogs.
Scheduled Task Isolation and Lifecycle Management
windowIdand isolated browser context; this window is created when a scheduled task session starts and is closed when the task completes or the session is deleted. [1] [2] [3]hiddenWindowIdand the browser context for scheduled tasks, ensuring all agent operations use the correct context. [1] [2]Prompt and Instruction Updates
<scheduled_task>section with critical rules (such as not grouping tabs and using the correctwindowId), and disabling tab grouping in strict rules for scheduled tasks. [1] [2] [3] [4] [5]Browser Context Formatting
windowIdandpageIdfor tabs, clarifying which window and page the agent is operating in—especially important for scheduled tasks.UI Improvements for Scheduled Tasks